import networkx as nx
# import matplotlib.pyplot as plt
import pandas as pd
import Distance_Statics as lp
import pickle
import os
import numpy as np
# import tensorflow as tf


NUM_REPEATS = 1
RANDOM_SEED = 0
FRAC_EDGES_HIDDEN = [0.5]
dimen = [0.1]

DEAL_NAME = 'grid_2d-15'
method = '1'
# Read in combined FB graph
combined_dir = 'D:/data-processed/{}-adj.pkl'.format(DEAL_NAME)
with open(combined_dir, 'rb') as f:
    adj = pickle.load(f)

Weak_Disses = []
Strong_Disses = []

### ---------- Run Link Prediction Tests ---------- ###

test_frac = 0.5
tmp_Weak_Disses = []
tmp_Strong_Disses = []

### ---------- Run Link Prediction Tests ---------- ###
# TRAIN_TEST_SPLITS_FOLDER = 'E:/data-split/ACT13/{}/'.format(DEAL_NAME)
TRAIN_TEST_SPLITS_FOLDER = 'D:/data/splited/ACT13_sample/1_1/{}/'.format(DEAL_NAME)

# Iterate over fractions of edges to hide
for j in range(NUM_REPEATS):
    print('第{}次执行'.format(j))
    experiment_name = '{}-{}-{}-hidden'.format(DEAL_NAME, test_frac, j)
    train_test_split_file = TRAIN_TEST_SPLITS_FOLDER + experiment_name + '.pkl'

    weak_diss, strong_diss = lp.calculate_scores(adj, test_frac=test_frac, val_frac=0,
                            random_state=RANDOM_SEED, verbose=2,
                            train_test_split_file=train_test_split_file, multip=0.6, dims=10, k=0.2, diff=1, method=method)

    tmp_Weak_Disses.append(weak_diss)
    tmp_Strong_Disses.append(strong_diss)

tmp_Weak_Diss = np.array(tmp_Weak_Disses).sum(axis=0) / 1.0
tmp_Strong_Diss = np.array(tmp_Strong_Disses).sum(axis=0) / 1.0
print(type(tmp_Weak_Diss[0]))

Weak_Diss = [float('{:.4f}'.format(i)) for i in tmp_Weak_Diss]
Strong_Diss = [float('{:.4f}'.format(i)) for i in tmp_Strong_Diss]

Weak_Disses.append(Weak_Diss)
Strong_Disses.append(Strong_Diss)

Diss = np.vstack((Weak_Disses, Strong_Disses))

# name = ['HOPE', 'LINE', 'Node2Vec', 'VGAE', 'SDNE']
#
# test = pd.DataFrame(columns=name, data=Diss)
# test.to_csv('{}-Dis.csv'.format(DEAL_NAME))

# test = pd.DataFrame(columns=name, data=Weak_Disses)
# test.to_csv('{}-Weak-Dis.csv'.format(DEAL_NAME))
#
# test = pd.DataFrame(columns=name, data=Strong_Disses)
# test.to_csv('{}-Strong-Dis.csv'.format(DEAL_NAME))



